<?php
/**
 * User: zwh
 * Time: 2016-10-24 15:56:56
 */

class MirrorOrderProductEsItem extends Eloquent
{
    protected $table = "mirror_order_product_esitem";
    
    /**
     * @Author:      zwh
     * @DateTime:    2016-10-26 10:00:35
     * @Description: 用于修改企业包配件数量
     */
    public static function changeProductItemNum($order_product,$opesi_old,$number,$amount){
        return DB::transaction(function () use ($order_product,$opesi_old,$number,$amount) {
            $opesi=MirrorOrderProductEsItem::find($opesi_old->id);
            $opesi->amount=$amount;
            $opesi->num=$number;
            $opesi->save();
    
            //订单应付金额及优惠信息将重新计算，废弃原有再优惠信息上加减
            MirrorOrders::calculate($order_product->order_id);
            return array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order_product->order_id));
        });
    }
    
    /**
     * @Author:      zwh
     * @DateTime:    2016-10-26 10:13:51
     * @Description: 用于修改企业包配件
     */
    public static function changeProductItem($order_product,$opi,$si,$wmcf,$new_item_type,$csi){
        return DB::transaction(function () use ($order_product,$opi,$si,$wmcf,$new_item_type,$csi) {
            $order=MirrorOrders::find($order_product->order_id);
            //更换耗材的加价系数
            // $wpc=WorkPartsCoefficient::where("car_model_name",$csi->model_level)->where("supply_brand_id",$si->brand_id)->where("supply_subject_id",$si->subject)->where("status",1)->first();
            // if($wpc){
            //     $wmcf->supply_coefficient=$wpc->coefficient;
            // }else{
            //     $wmcf->supply_coefficient=1;
            // }
            
    
            // if($new_item_type==0){
                // $ss=SupplySeries::find($si->series_id);
                $item_info=SupplyItem::getCacheItemInfo($si->id);
                $opi->item_name=$item_info->name;
                $opi->amount=$si->amount;
                $opi->item_id=$si->id;
                $opi->unit=$item_info->unit?$item_info->unit:'';
            // }else{
            //     $opi->item_name=$si->series_name." ".$si->model;
            //     $opi->amount=$si->amount;
            //     $opi->item_id=$si->id;
            //     $opi->unit=$si->unit;
            // }
            $opi->item_type=$new_item_type;
            $opi->is_adapter=1;
            $opi->save();
    
            //订单应付金额及优惠信息将重新计算，废弃原有再优惠信息上加减
            MirrorOrders::calculate($order_product->order_id);
            return array('code' => 0, 'msg' => 'ok', 'result' => array("order_id"=>$order_product->order_id));
        });
    }
}
